﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GeneratorLib.DB;
using GeneratorLib.DB.Connectios;
using GeneratorLib.DB.Schemas;

namespace GeneratorCode.Pasys
{
    public class Converts
    {
        public static string ConvertsMethodName(FieldInfo field)
        {
            return ConvertsMethodName(field,false);
        }
        public static string ConvertsMethodName(FieldInfo field,bool chkNullabled)
        {
            string methodName = "";
            switch (field.FieldType.MapName.ToLower())
            {
                case "int":
                    methodName = "Converts.ToTryInt({0},0)";
                    break;
                case "datetime":
                    if (!chkNullabled)
                        methodName = "Converts.ToTryDateTime({0},DateTime.MinValue)";
                    else
                        methodName = "Converts.ToTryDateTimeNullable({0},null)";
                    break;
                case "decimal":
                    methodName = "Converts.ToTryDecimal({0},0)";
                    break;
                case "bool":
                    methodName = "Converts.ToTryBool({0},false)";
                    break;
                case "string":
                    methodName = "Converts.ToTryString({0},\"\")";
                    break;
                case "double":
                    methodName = "Converts.ToTryDouble({0},0)";
                    break;
                case "byte[]":
                    methodName = "(byte[]){0}";
                    break;
                default:
                    methodName = "{0}";
                    break;
            }

            return methodName;
        }


    }
}
